package com.ruoyi.web.controller.manage;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.TypeTemplate;
import com.ruoyi.manage.service.ITypeTemplateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图片模板管理Controller
 * 
 * @author ruoyi
 * @date 2021-01-27
 */
@RestController
@RequestMapping("/manage/template")
public class TypeTemplateController extends BaseController
{
    @Autowired
    private ITypeTemplateService typeTemplateService;

    /**
     * 查询图片模板管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(TypeTemplate typeTemplate)
    {
        startPage();
        List<TypeTemplate> list = typeTemplateService.selectTypeTemplateList(typeTemplate);
        return getDataTable(list);
    }

    /**
     * 导出图片模板管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:template:export')")
    @Log(title = "图片模板管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TypeTemplate typeTemplate)
    {
        List<TypeTemplate> list = typeTemplateService.selectTypeTemplateList(typeTemplate);
        ExcelUtil<TypeTemplate> util = new ExcelUtil<TypeTemplate>(TypeTemplate.class);
        return util.exportExcel(list, "template");
    }

    /**
     * 获取图片模板管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:template:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(typeTemplateService.selectTypeTemplateById(id));
    }

    /**
     * 新增图片模板管理
     */
    @PreAuthorize("@ss.hasPermi('manage:template:add')")
    @Log(title = "图片模板管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TypeTemplate typeTemplate)
    {
        return toAjax(typeTemplateService.insertTypeTemplate(typeTemplate));
    }

    /**
     * 修改图片模板管理
     */
    @PreAuthorize("@ss.hasPermi('manage:template:edit')")
    @Log(title = "图片模板管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TypeTemplate typeTemplate)
    {
        return toAjax(typeTemplateService.updateTypeTemplate(typeTemplate));
    }

    /**
     * 删除图片模板管理
     */
    @PreAuthorize("@ss.hasPermi('manage:template:remove')")
    @Log(title = "图片模板管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(typeTemplateService.deleteTypeTemplateByIds(ids));
    }
}
